/*
 * dnet_userIF.c
 *
 *  Author: lifeng
 */

#include <string.h>
#include "dnet_userIF.h"

unsigned long lfSERIALNO;      //设备序列号

unsigned char dnet_macid,dnet_btr;    //macid：0~63  btr：通讯速率  0-125K  1-250K  2-500K

unsigned short POLL_CSM_LEN,POLL_PRU_LEN;        //poll IO 收发长度
//pollIO 收发缓冲区
unsigned char pollOUTBuffer[16];
unsigned char pollINBuffer[16];
unsigned char pollotbuf[16];
unsigned char pollinbuf[16];

//设备名称和长度
unsigned char ProductName[16];
unsigned short PNAME_LEN;

//指示LED状态
unsigned char flag_msled;    //0-off  1-正常(绿）  2-等待就绪(绿闪)  3-错误(红闪)  4-自检中(黄闪)
unsigned char flag_nsled;    //0-off  1-正常(绿)  2-无连接(绿闪)  3-通讯错误(红闪)  4-错误(红)


void dndata_init(unsigned char macid,unsigned char btr)
{
	lfSERIALNO=1000;          //一般可读取单片机ID生成

    memset(pollOUTBuffer,0,16);
    memset(pollINBuffer,0,16);
    memset(pollotbuf,0,16);
    memset(pollinbuf,0,16);

    dnet_macid=macid;
    dnet_btr=btr;               //125K

    memcpy(ProductName,PRODUCTNAME,PNAMEg_LEN);
    PNAME_LEN=PNAMEg_LEN;
    POLL_CSM_LEN=8;         //poll IO consum len
    POLL_PRU_LEN=14;         //poll IO product len
}


int getEXattr1(int aid,unsigned char * buf)
{
    int len=0;
    switch(aid){
    case 1:
        buf[0]=0;buf[1]=1;     //填入参数值
        len=2;                 //参数长度
        break;
    case 2:
        buf[0]=10;
        len=1;
        break;
    case 3:
        //其它参数
        break;
    default:
        break;
    }
    return len;
}

int getEXattrSLEN1(int aid)
{
    int len=0;
    switch(aid){
    case 1:len=2;break;
    case 2:len=1;break;
    case 3:len=1;break;
    case 4:len=2;break;
    case 5:len=1;break;
    case 6:len=1;break;
    case 11:len=1;break;
    case 12:len=1;break;
    case 13:len=2;break;
    case 14:len=1;break;
    default:len=0;break;
    }
    return len;
}

void setEXattr1(int aid,unsigned char * buf)
{
    //unsigned short crc1;
    switch(aid){
    case 1:
        //crc1=buf[0]*256+buf[1];
        /*示例，检查合法性并设置参数
         * if(crc1<FRQ_H_MIN){crc1=FRQ_H_MIN;}
        else if(crc1>FRQ_H_MAX){crc1=FRQ_H_MAX;}
        if(por_run.ctl_mode==2){
            if(crc1.b!=spdy_mb.start_FRQ){
                spdy_mb.start_FRQ=crc1;
            }
        }*/
        break;
    case 2:
        //其它参数处理
        break;
    case 3:
    	//其它参数处理

        break;
    default:
        break;
    }
}
